package com.dong.dingtalk_demo.handle;

import com.dong.dingtalk_demo.util.DingTalkUtil;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

@Component
public class AlarmHandler {

    public AlarmHandler() {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
        AtomicInteger j = new AtomicInteger(0);
        scheduledExecutorService.scheduleAtFixedRate(() -> {
//            if (j.incrementAndGet()%3 == 0){
//                DingTalkUtil.postWithJson("内存用到"+j+"G了,赶快处理！！！",0);
//            }else if (j.incrementAndGet()%3 == 1){
            if (j.incrementAndGet() == 10){
                DingTalkUtil.postWithJson("有"+j+"个人会见不了了,赶快处理！！！",1);
                j.set(0);
            }
//            }else {
//                DingTalkUtil.postWithJson("有"+j+"台电话打不了了,你弄啥来！！！",2);
//            }

            // 参数 延迟时间 0 执行间隔 15 单位 TimeUnit.SECONDS 秒
        }, 0, 5, TimeUnit.SECONDS);
    }
}
